IdeaBlade.Core Assembly > IdeaBlade.Core Namespace : PropertyInterceptor<TInstance,TValue,TArgs> Class |
'Declaration
Public Class PropertyInterceptor (Of TInstance,TValue,TArgs As PropertyInterceptorArgs(Of TInstance,TValue)) Inherits PropertyInterceptor
'Usage
Dim instance As PropertyInterceptor(Of TInstance,TValue,TArgs)
public class PropertyInterceptor<TInstance,TValue,TArgs> : PropertyInterceptor where TArgs: PropertyInterceptorArgs<TInstance,TValue>
Any number of PropertyInterceptorActions may be defined for each interceptor. You add these actions using attributes and AddAction(PropertyInterceptorTiming,Action<TArgs>).
You may also define PropertyInterceptors and actions on non-Entity types.
public void Sample() { // Sample showing a mix of attribute and dynamic actions, on both base and derived types. // Add dynamic actions on Entity to affect any property: PropertyInterceptorManager.CurrentInstance.AddAction( new PropertyInterceptorAction<PropertyInterceptorArgs<Entity, Object>>( typeof(Entity), null, PropertyInterceptorMode.BeforeSet, (args) => Console.WriteLine("Entity BeforeSet"), 0.0, "A")); PropertyInterceptorManager.CurrentInstance.AddAction( new PropertyInterceptorAction<PropertyInterceptorArgs<Entity, Object>>( typeof(Entity), null, PropertyInterceptorMode.AfterSet, (args) => Console.WriteLine("Entity AfterSet"), 0.0, "B")); // Look at all before set actions affecting customer company name foreach (var action in Customer.CompanyNameEntityProperty.SetterInterceptor.GetActions(typeof(Customer), PropertyInterceptorMode.BeforeSet)) { Console.WriteLine(action.Key + ", order = " + action.Order); } // Now look at all after set actions affecting customer company name foreach (var action in Customer.CompanyNameEntityProperty.SetterInterceptor.GetActions(typeof(Customer), PropertyInterceptorMode.AfterSet)) { Console.WriteLine(action.Key + ", order = " + action.Order); } // Now get a customer entity and set company name - see output for actions invoked. DomainModelEntityManager mgr = DomainModelEntityManager.DefaultManager; Customer c1 = mgr.Customers.First(); c1.CompanyName = "Books N Things"; } public partial class Customer { [BeforeSet(Key = "CustomerBeforeAction1")] public void BeforeSetAnyCustomerProperty(IEntityPropertySetInterceptorArgs args) { Console.WriteLine("Customer any - before setting " + args.EntityProperty.Name); } [BeforeSet("CompanyName", Key = "CustomerBeforeAction2")] public void BeforeSetCompanyName(IEntityPropertySetInterceptorArgs args) { Console.WriteLine("Customer companyname - before setting company name"); } [AfterSet(Key="CustomerAfterAction1")] public void AfterSetAnyCustomerProperty(IEntityPropertySetInterceptorArgs args) { Console.WriteLine("Customer any - After setting " + args.EntityProperty.Name); } [AfterSet("CompanyName", Key="CustomerAfterAction2")] public void AfterSetCompanyName(IEntityPropertySetInterceptorArgs args) { Console.WriteLine("Customer companyname - After setting company name"); } }
System.Object
IdeaBlade.Core.PropertyInterceptor
IdeaBlade.Core.PropertyInterceptor<TInstance,TValue,TArgs>
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2